/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PostPurchaseFrame.java
 *
 * Created on Jan 18, 2010, 10:30:34 PM
 */

package org.acmwustl.bubble.gui;

import java.awt.Dimension;
import javax.swing.SwingWorker;
import org.acmwustl.bubble.util.PriceToString;
import org.acmwustl.bubble.windowutils.WindowUtils;

/**
 *
 * @author Tyler
 */
public class PostPaymentFrame extends javax.swing.JFrame {

    /** Creates new form PostPurchaseFrame */
    public PostPaymentFrame(int newBalanceInCents) {
        initComponents();

        CloseTimer ct = new CloseTimer(3500);
        ct.execute();

        setSize(new Dimension(1024,768));
        WindowUtils.centerWindow(this);

        newBalanceLabel.setText(PriceToString.getPriceAsString(newBalanceInCents));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        newBalanceLabel = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 36));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Thank you for your purchase!");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Your new balance is:");

        newBalanceLabel.setFont(new java.awt.Font("Tahoma", 0, 48));
        newBalanceLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        newBalanceLabel.setText("$0.00");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Window will close automatically.");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(newBalanceLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(80, 80, 80)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(newBalanceLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 216, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private class CloseTimer extends SwingWorker {
        long time;
        long lastMillis;

        public CloseTimer(long length) {
            time = length;
            lastMillis = System.currentTimeMillis();
        }

        @Override
        protected Object doInBackground() throws Exception {
            while(time > 0) {
                long diff = System.currentTimeMillis() - lastMillis;
                lastMillis = System.currentTimeMillis();
                time -= diff;
                Thread.sleep(500);
            }
            dispose();
            return null;
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel newBalanceLabel;
    // End of variables declaration//GEN-END:variables

}
